import { STATUS_OPTIONS, STATUS_OPTIONS_ARRAY } from './init'
import { mapGetters } from 'vuex'
import { getPageBtnHash } from '@/permission'

export default {
  computed: {
    ...mapGetters(['dict']),
    // 表格默认prop
    tableProp() {
      return {
        stripe: true,
        border: true,
        fit: true,
        //height: this.tableBodyHeight
      }
    }
  },
  data() {
    return {
      console, // 以便在 template 中打印
      Promise, // 以便在 template 中使用 Promise
      hasBtn: getPageBtnHash(),
      options: {
        status: STATUS_OPTIONS,
        statusArray: STATUS_OPTIONS_ARRAY,
      },
      elPaginationProps: {
        background: true,
        layout: 'total, sizes, prev, pager, next, jumper'
      },
      popSwitchProps: value => ({
        value,
        ...(this.hasBtn[STATUS_OPTIONS[value ^ 1]]
          ? {
            elPopconfirmProps: {
              title: `确认${STATUS_OPTIONS[value ^ 1]}吗？`
            }
          }
          : {
            disabled: true,
            elPopoverProps: {
              content: `<i class='el-icon-warning'/> 权限不足`
            }
          }),
        key: new Date().getTime()
      }),
      //tableBodyHeight: undefined
    }
  },
  /* beforeDestroy() {
    window.removeEventListener('resize', this.computeTableHeight)
  },
  mounted() {
    this.computeTableHeight()
    window.addEventListener('resize', this.computeTableHeight)
  },
  methods: {
    // 动态计算表格高度
    computeTableHeight() {
      let tableDom = document.querySelector('.app-container>.el-table')
      if (tableDom) {
        const tableOffsetTop = tableDom.getBoundingClientRect().top // 表格顶部位置
        let tableBodyHeight = window.innerHeight - tableOffsetTop - 20 // 表格内部区域高度
        this.tableBodyHeight =
          tableBodyHeight < 300 ? undefined : tableBodyHeight // 表格区域小于300的话就不设置了
      }
    }
  } */
}
